package com.xw.base.entity.exception;

import org.apache.commons.lang3.StringUtils;

public class BaseException  extends RuntimeException{

    protected IException iException;

    public BaseException() {
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseException(IException iException, Throwable cause) {
        super(cause);
        this.iException = iException;
    }

    public BaseException(IException iException) {
        this.iException = iException;
    }

    public String getFullMessage() {
        return this.getFullMessage(this);
    }

    public IException getiException() {
        return this.iException;
    }

    public void setiException(IException iException) {
        this.iException = iException;
    }

    private String getFullMessage(Throwable ex) {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isEmpty(ex.getMessage())) {
            builder.append(ex.toString());
        } else {
            builder.append(ex.getMessage());
        }

        if (ex.getCause() != null) {
            builder.append(" caused by: [ ").append(this.getFullMessage(ex.getCause())).append(" ]");
        }

        return builder.toString();
    }

}
